<template>
	<view class="flex-colume-start startPage">
		<view style="height: 30rpx;"></view>
		<view class="flex-row-center"
			style="background-color: white; width: 640rpx; border-radius: 20rpx; height: 249rpx;">
			<image src="/static/bg1.png" style="width: 580rpx; height: 245rpx;"></image>
		</view>
		<view class="flex-colume-start"
			style="margin-top: 30rpx; width: 640rpx; border-radius: 20rpx; padding: 40rpx; box-sizing: border-box;">
			<view class="btn1" style="margin-top: 40rpx;" @click="sureBtnClick(0)">综合评分查询</view>
			<view class="btn1" style="margin-top: 40rpx;" @click="sureBtnClick(1)">备案机型查询</view>
			<view class="btn1" style="margin-top: 40rpx;" @click="sureBtnClick(2)">信用额度评测</view>

		</view>
		<u-popup mode='center' :show="showPop1" :overlay="true" :closeable="false" :round="15"
			:closeOnClickOverlay="false" @close="showPop1 = false" bgColor="transparent">

			<view class="flex-colume-start"
				style="position: relative; padding: 30rpx; box-sizing: border-box; border-radius: 20rpx; background-color: white; width: 660rpx;">
				<!-- <image :src="url3" style="width: 500rpx;" mode="widthFix"></image> -->
				<view style="font-size: 32rpx; font-weight: 700;">{{status == 0?'待申请':'申请中'}}</view>
				
				
				<view style="width: 100%; height: 80rpx; margin-top: 35rpx; " >
					<u--input v-model="nickname" placeholder="请输入名字"
						style="font-size: 28rpx; height: 80rpx; width: 100%;" v-if="status == 0"></u--input>
						<view v-else style="text-align: center; font-size: 28rpx; color: rgb(153, 153, 153);">正在等待审核，请稍后再试</view>
				</view>

				<view style="width: 300rpx; margin-top: 40rpx;" v-if="status == 0">
					<u-button v-if="status == 0" :loading="loading1" @click="uploadBtnClick()"
						:customStyle="btnStyle">申请</u-button>
				</view>

			</view>
			<image src="/static/arrow/close-gray.png" @click="showPop1 = false"
				style="position: absolute; right: 10rpx; top: 10rpx; padding: 15rpx; box-sizing: border-box; height: 50rpx; width: 50rpx;"></image>


		</u-popup>
	</view>
</template>

<script>
	import {
		login,
		apply
	} from '@/api/api'
	export default {
		data() {
			return {
				name: '',
				card: '',
				canShow: false,
				status: 0,
				showPop1: false,
				loading1: false,
				nickname: '',
				btnStyle: {
					color: 'white',
					backgroundColor: 'rgb(0, 82, 144)',
					fontSize: '40rpx',
					fontWeight: '500',
					borderRadius: '10rpx'
				}

			}
		},
		onShow() {
			var token = uni.getStorageSync('hqt-mix-token')
			if (!this.canShow) {
				uni.showLoading()
				uni.login({
					success: (res) => {
						setTimeout(res1 => {
							this.requestLogin(res.code)
						}, 500)
					},
					fail: () => {
						uni.hideLoading()
					}
				})


			}

		},
		methods: {
			requestLogin(code) {
				login({
					open_id_code: code
				}).then(res => {
					uni.hideLoading()
					if (res.code == 200) {
						var data = res.data
						uni.setStorageSync('hqt-mix-token', data.info.utoken)
						this.status = Number(data.info.status)
						if (this.status == 1) {
							this.canShow = true
						} else {
							this.showPop1 = true
						}

						return

					}
					console.log('11', res)
					// this.showSimpleMessage(res.message)
					uni.showModal({
						content: res.message,
						showCancel: false
					})

				})

			},
			sureBtnClick(index) {
				if (!this.canShow) {
					this.showPop1 = true
					return

				}
				if (index == 0) {
					uni.navigateTo({
						url: '/pages/index/index'
					})
					return
				}
				if (index == 1) {
					uni.navigateTo({
						url: '/pages/second/second'
					})
					return
				}
				if (index == 2) {
					uni.navigateTo({
						url: '/pages/third/third'
					})
					return
				}

			},
			uploadBtnClick() {
				if (!this.nickname) {
					uni.showModal({
						content: '请输入姓名',
						showCancel: false
					})
					return

				}
				this.loading1 = true
				apply({
					nickname: this.nickname
				}).then(res => {
					this.loading1 = false
					if (res.code == 200) {
						var data = res.data
						this.showPop1 = false
						this.status = 9
						uni.showModal({
							content: res.message,
							showCancel: false
						})

						return

					}
					console.log('11', res)
					// this.showSimpleMessage(res.message)
					uni.showModal({
						content: res.message,
						showCancel: false
					})
				})
			}


		}
	}
</script>

<style lang="scss" scoped>
	.startPage {

		.btn1 {
			width: 100%;
			height: 84rpx;
			line-height: 84rpx;
			color: white;
			font-size: 30rpx;
			font-weight: 600;
			border-radius: 20rpx;
			background-color: rgb(0, 82, 144);
			text-align: center;
		}

	}

	.uploadBtn {
		background-color: rgb(0, 82, 144);
	}
</style>